﻿using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using ERP.Localization;
using ERP.Abp.Account.Localization;
using Volo.Abp.Authorization.Permissions;
using Volo.Abp.UI.Navigation;
using Volo.Abp.Users;
using ERP.Permissions;

namespace ERP.Blazor.Menus;



public class ERPMenuContributor : IMenuContributor
{
    private readonly IConfiguration _configuration;

    public ERPMenuContributor(IConfiguration configuration) 
    {
        _configuration = configuration;
    }

    public async Task ConfigureMenuAsync(MenuConfigurationContext context)
    {
        //if (context.Menu.Name == StandardMenus.Main)
        {
            await ConfigureMainMenuAsync(context);
        }
        //  else if (context.Menu.Name == StandardMenus.User)
        {
            await ConfigureUserMenuAsync(context);
        }
    }

    private Task ConfigureMainMenuAsync(MenuConfigurationContext context)
    {
        var l = context.GetLocalizer<ERPResource>();

        context.Menu.Items.Insert(
           0, new ApplicationMenuItem(WorkMenus.Work, l["Menu:Work"], "#", icon: "Home") 
                .AddItem(new ApplicationMenuItem(name:WorkMenus.Home, displayName:l["Menu:Home"], $"/", icon: "Home"))
                .AddItem(new ApplicationMenuItem(name: WorkMenus.Work, displayName: l["Menu:StartFlow"],url: $"test2?a={new Random().NextDouble()}", icon: "radar-chart",requiredPermissionName: ERPPermissions.Work))
                .AddItem(new ApplicationMenuItem(name:WorkMenus.Todo, displayName: l["Menu:Todo"], url: $"test2?a={new Random().NextDouble()}", icon: "highlight", requiredPermissionName: ERPPermissions.Todo))
                .AddItem(new ApplicationMenuItem(name:WorkMenus.Todoed, displayName: l["Menu:Todoed"], url: $"test2?a={new Random().NextDouble()}", icon: "fund", requiredPermissionName: ERPPermissions.Todoed))
                .AddItem(new ApplicationMenuItem(name:WorkMenus.MyApply, displayName: l["Menu:MyApply"], url: $"test2?a={new Random().NextDouble()}", icon: "sliders", requiredPermissionName: ERPPermissions.MyApply))
                .AddItem(new ApplicationMenuItem(name:WorkMenus.MyCirculated, displayName: l["Menu:MyCirculated"], url: $"test2?a={new Random().NextDouble()}", icon: "audit", requiredPermissionName: ERPPermissions.MyCirculated))
                .AddItem(new ApplicationMenuItem(name:WorkMenus.Reading, displayName: l["Menu:Reading"], url: $"test2?a={new Random().NextDouble()}", icon: "book", requiredPermissionName: ERPPermissions.Reading))
                .AddItem(new ApplicationMenuItem(name:WorkMenus.Readed, displayName: l["Menu:Readed"], url: $"test2?a={new Random().NextDouble()}", icon: "build", requiredPermissionName: ERPPermissions.Readed))
        );


        context.Menu.Items.Insert(
         1, new ApplicationMenuItem(name:SysMenus.SysteMmanager, displayName: l["Menu:SysteMmanager"], "#", icon: "setting", requiredPermissionName: ERPPermissions.SysteMmanager)
              .AddItem(new ApplicationMenuItem(name:SysMenus.UserMmanager, displayName: l["Menu:UserMmanager"], url: "identity/users", icon: "user", requiredPermissionName: ERPPermissions.UserMmanager))
              .AddItem(new ApplicationMenuItem(name:SysMenus.OrgMmanager, displayName: l["Menu:OrgMmanager"], url: "identity/orgs", icon: "appstore", requiredPermissionName: ERPPermissions.OrgMmanager))
              .AddItem(new ApplicationMenuItem(name:SysMenus.RoleMmanager, displayName: l["Menu:RoleMmanager"], url: "identity/roles", icon: "ci", requiredPermissionName: ERPPermissions.RoleMmanager))
              .AddItem(new ApplicationMenuItem(name:SysMenus.TenantMmanager, displayName: l["Menu:TenantMmanager"], url: "tenant-management/tenants", icon: "experiment", requiredPermissionName: ERPPermissions.TenantMmanager ))
        );



        //人事管理
        context.Menu.Items.Insert(
        2, new ApplicationMenuItem("personnel", l["Menu:PersonnelMmanager"], "#", icon: "gitlab") 
           .AddItem(new ApplicationMenuItem("kjh", "员工管理", "#", icon: "form") 
                   .AddItem(new ApplicationMenuItem("a", "员工档案", $"test2?a={new Random().NextDouble()}", icon: "cluster") )
                   .AddItem(new ApplicationMenuItem("a2", "员工关怀", $"test2?a={new Random().NextDouble()}", icon: "bulb") )
                   .AddItem(new ApplicationMenuItem("a3", "入职", $"test2?a={new Random().NextDouble()}", icon: "container") )
                   .AddItem(new ApplicationMenuItem("a4", "转正", $"test2?a={new Random().NextDouble()}", icon: "credit-card") )
                   .AddItem(new ApplicationMenuItem("a5", "调动", $"test2?a={new Random().NextDouble()}", icon: "crown") )
                   .AddItem(new ApplicationMenuItem("a6", "离职", $"test2?a={new Random().NextDouble()}", icon: "format-painter"))
                   .AddItem(new ApplicationMenuItem("a7", "人事异动查询", $"test2?a={new Random().NextDouble()}", icon: "inbox"))
                   .AddItem(new ApplicationMenuItem("a8", "合同管理", $"test2?a={new Random().NextDouble()}", icon: "interaction"))
                   .AddItem(new ApplicationMenuItem("a9", "培训管理", $"test2?a={new Random().NextDouble()}", icon: "layout"))
                   .AddItem(new ApplicationMenuItem("a10", "招聘管理", $"test2?a={new Random().NextDouble()}", icon: "picture"))
            )
           .AddItem(new ApplicationMenuItem("ceffs", "假勤管理", "#", icon: "form")
                   .AddItem(new ApplicationMenuItem("b1", "打卡管理", $"test2?a={new Random().NextDouble()}", icon: "schedule"))
                   .AddItem(new ApplicationMenuItem("b2", "请假管理", $"test2?a={new Random().NextDouble()}", icon: "security-scan"))
                   .AddItem(new ApplicationMenuItem("b3", "加班管理", $"test2?a={new Random().NextDouble()}", icon: "robot"))
                   .AddItem(new ApplicationMenuItem("b4", "外出管理", $"test2?a={new Random().NextDouble()}", icon: "rotate-right"))
                   .AddItem(new ApplicationMenuItem("b5", "假期余额管理", $"test2?a={new Random().NextDouble()}", icon: "table"))
                   .AddItem(new ApplicationMenuItem("b6", "排班管理", $"test2?a={new Random().NextDouble()}", icon: "solution"))

                   .AddItem(new ApplicationMenuItem("c1", "请假设置", $"test2?a={new Random().NextDouble()}", icon: "reconciliation"))
                   .AddItem(new ApplicationMenuItem("c2", "加班设置", $"test2?a={new Random().NextDouble()}", icon: "read"))
                   .AddItem(new ApplicationMenuItem("c3", "考勤设置", $"test2?a={new Random().NextDouble()}", icon: "merge-cells"))

                   .AddItem(new ApplicationMenuItem("c4", "各类假勤报表", "#", icon: "mobile"))
           )
           .AddItem(new ApplicationMenuItem("abc", "薪酬管理", "#", icon: "group")
                  .AddItem(new ApplicationMenuItem("d1", "薪资档案", $"test2?a={new Random().NextDouble()}", icon: "folder-view"))
                  .AddItem(new ApplicationMenuItem("d2", "社保公积金", $"test2?a={new Random().NextDouble()}", icon: "hdd"))
                  .AddItem(new ApplicationMenuItem("d3", "专项扣除", $"test2?a={new Random().NextDouble()}", icon: "copy"))
                  .AddItem(new ApplicationMenuItem("d4", "个人累计综合缴纳", $"test2?a={new Random().NextDouble()}", icon: "youtube"))
                  .AddItem(new ApplicationMenuItem("d5", "考勤结算", $"test2?a={new Random().NextDouble()}", icon: "windows"))
                  .AddItem(new ApplicationMenuItem("d6", "业绩结算", $"test2?a={new Random().NextDouble()}", icon: "twitter"))
                  .AddItem(new ApplicationMenuItem("d7", "绩效考核结算", $"test2?a={new Random().NextDouble()}", icon: "codepen"))
                  .AddItem(new ApplicationMenuItem("d8", "离职结算", $"test2?a={new Random().NextDouble()}", icon: "instagram"))
                  .AddItem(new ApplicationMenuItem("d9", "薪酬计算", $"test2?a={new Random().NextDouble()}", icon: "reddit"))
                  .AddItem(new ApplicationMenuItem("ee", "薪酬发放", $"test2?a={new Random().NextDouble()}", icon: "codepen"))
                  .AddItem(new ApplicationMenuItem("dd", "薪资结转凭证", $"test2?a={new Random().NextDouble()}", icon: "dribbble-square"))
           )
       );





        //财务管理
        context.Menu.Items.Insert(
          3, new ApplicationMenuItem("FinancialMmanager", l["Menu:FinancialMmanager"], $"test2?a={new Random().NextDouble()}", icon: "account-book")
                 .AddItem(new ApplicationMenuItem("f1", "凭证管理", "Flow/Applicatoin", icon: "aim"))
                 .AddItem(new ApplicationMenuItem("f2", "帐薄", $"test2?a={new Random().NextDouble()}", icon: "alert")
                        .AddItem(new ApplicationMenuItem("f3", "明细帐", $"test2?a={new Random().NextDouble()}", icon: "apartment"))
                        .AddItem(new ApplicationMenuItem("f4", "总帐", $"test2?a={new Random().NextDouble()}", icon: "codepen"))
                        .AddItem(new ApplicationMenuItem("f5", "数量金额明细帐", $"test2?a={new Random().NextDouble()}", icon: "api"))
                        .AddItem(new ApplicationMenuItem("f6", "数量金额明总帐", $"test2?a={new Random().NextDouble()}", icon: "appstore-add"))
                        .AddItem(new ApplicationMenuItem("f7", "核算项目明细帐", $"test2?a={new Random().NextDouble()}", icon: "calculator"))
                        .AddItem(new ApplicationMenuItem("f8", "核算项目余额表", $"test2?a={new Random().NextDouble()}", icon: "codepen"))
                )
               .AddItem(new ApplicationMenuItem("g2", "固定资产管理", $"test2?a={new Random().NextDouble()}", icon: "clear"))
               .AddItem(new ApplicationMenuItem("g3", "报表", "Flow/Applicatoin", icon: "cloud-server")
                       .AddItem(new ApplicationMenuItem("gg1", "资产负债表", $"test2?a={new Random().NextDouble()}", icon: "comment"))
                       .AddItem(new ApplicationMenuItem("gg12", "利润表", $"test2?a={new Random().NextDouble()}", icon: "control"))
                       .AddItem(new ApplicationMenuItem("gg13", "现金流量表", $"test2?a={new Random().NextDouble()}", icon: "codepen"))
                       .AddItem(new ApplicationMenuItem("gg14", "费用明细表", $"test2?a={new Random().NextDouble()}", icon: "delete-row"))
               )
              .AddItem(new ApplicationMenuItem("h1", "设置", $"test2?a={new Random().NextDouble()}",icon: "environment")
                      .AddItem(new ApplicationMenuItem("h2", "科目管理", $"test2?a={new Random().NextDouble()}", icon: "fire"))
                      .AddItem(new ApplicationMenuItem("h", "初始余额表", $"test2?a={new Random().NextDouble()}", icon: "funnel-plot"))
                      .AddItem(new ApplicationMenuItem("h78", "现金流量初始余额", $"test2?a={new Random().NextDouble()}", icon: "mail"))
              )

          );


        //客户关系管理
        context.Menu.Items.Insert(
          4, new ApplicationMenuItem("ClientRealation","客户关系管理", $"test2?a={new Random().NextDouble()}", icon: "account-book")
                 .AddItem(new ApplicationMenuItem("ClientRealation1", "客户", $"test2?a={new Random().NextDouble()}", icon: "aim"))
                 .AddItem(new ApplicationMenuItem("ClientRealation2", "合同", $"test2?a={new Random().NextDouble()}", icon: "aim"))
                 .AddItem(new ApplicationMenuItem("ClientRealation3", "联系人", $"test2?a={new Random().NextDouble()}", icon: "aim"))
                 .AddItem(new ApplicationMenuItem("ClientRealation4", "回款", $"test2?a={new Random().NextDouble()}", icon: "aim"))
                 .AddItem(new ApplicationMenuItem("ClientRealation5", "发票", $"test2?a={new Random().NextDouble()}", icon: "aim"))
                 .AddItem(new ApplicationMenuItem("ClientRealation6", "产品", $"test2?a={new Random().NextDouble()}", icon: "aim"))
                 .AddItem(new ApplicationMenuItem("ClientRealation7", "任务", $"test2?a={new Random().NextDouble()}", icon: "aim"))

          );
        //进销存
        context.Menu.Items.Insert(
          5, new ApplicationMenuItem("EntersSellSave", "进销存", $"test2?a={new Random().NextDouble()}", icon: "account-book")
                 .AddItem(new ApplicationMenuItem("Enters", "采购", $"test2?a={new Random().NextDouble()}", icon: "aim")
                    .AddItem(new ApplicationMenuItem("Enters3", "供应商", $"test2?a={new Random().NextDouble()}", icon: "apartment"))
                    .AddItem(new ApplicationMenuItem("Enters1", "采购订单", $"test2?a={new Random().NextDouble()}", icon: "apartment"))
                    .AddItem(new ApplicationMenuItem("Enters2", "采购退货单", $"test2?a={new Random().NextDouble()}", icon: "apartment"))
                 )
                 .AddItem(new ApplicationMenuItem("Sell", "销售", $"test2?a={new Random().NextDouble()}", icon: "aim")
                      .AddItem(new ApplicationMenuItem("Sell", "销售订单", $"test2?a={new Random().NextDouble()}", icon: "apartment"))
                      .AddItem(new ApplicationMenuItem("Sel2", "销售退货单", $"test2?a={new Random().NextDouble()}", icon: "apartment"))
                 )
                 .AddItem(new ApplicationMenuItem("Save", "库存管理", $"test2?a={new Random().NextDouble()}", icon: "aim")
                    .AddItem(new ApplicationMenuItem("Save1", "仓库", $"test2?a={new Random().NextDouble()}", icon: "apartment"))
                    .AddItem(new ApplicationMenuItem("Save2", "库存", $"test2?a={new Random().NextDouble()}", icon: "apartment"))
                    .AddItem(new ApplicationMenuItem("Save3", "入库", $"test2?a={new Random().NextDouble()}", icon: "apartment"))
                    .AddItem(new ApplicationMenuItem("Save4", "出库", $"test2?a={new Random().NextDouble()}", icon: "apartment"))
                    .AddItem(new ApplicationMenuItem("Save5", "调拨", $"test2?a={new Random().NextDouble()}", icon: "apartment"))
                    .AddItem(new ApplicationMenuItem("Save6", "盘点", $"test2?a={new Random().NextDouble()}", icon: "apartment"))
                    .AddItem(new ApplicationMenuItem("Save7", "出入库明细", $"test2?a={new Random().NextDouble()}", icon: "apartment"))
                 )
                 .AddItem(new ApplicationMenuItem("Products", "产品", $"test2?a={new Random().NextDouble()}", icon: "aim"))
                 .AddItem(new ApplicationMenuItem("FNMG", "财务", $"test2?a={new Random().NextDouble()}", icon: "aim")
                    .AddItem(new ApplicationMenuItem("FNMG1", "回款", $"test2?a={new Random().NextDouble()}", icon: "apartment"))
                    .AddItem(new ApplicationMenuItem("FNMG2", "付款", $"test2?a={new Random().NextDouble()}", icon: "apartment"))
                 )
                

          );



        //营运系统
        context.Menu.Items.Insert(
          6, new ApplicationMenuItem("OperatingMmanager", l["Menu:OperatingMmanager"], $"test2?a={new Random().NextDouble()}", icon: "account-book")
                 .AddItem(new ApplicationMenuItem("OperatingMmanager4", "人力资源行业务", $"test2?a={new Random().NextDouble()}", icon: "aim"))
                 .AddItem(new ApplicationMenuItem("OperatingMmanager3", "生产制造行业", $"test2?a={new Random().NextDouble()}", icon: "aim")

                        .AddItem(new ApplicationMenuItem("h5133", "设备管理", $"test2?a={new Random().NextDouble()}", icon: "fire"))
                        .AddItem(new ApplicationMenuItem("h45133", "工艺管理", $"test2?a={new Random().NextDouble()}", icon: "fire"))
                        .AddItem(new ApplicationMenuItem("h416313", "物料管理", $"test2?a={new Random().NextDouble()}", icon: "fire"))
                        .AddItem(new ApplicationMenuItem("h13", "计划管理", $"test2?a={new Random().NextDouble()}", icon: "fire"))
                        .AddItem(new ApplicationMenuItem("h1g332", "安全管理", $"test2?a={new Random().NextDouble()}", icon: "fire"))
                        .AddItem(new ApplicationMenuItem("4h13", "质量管理", $"test2?a={new Random().NextDouble()}", icon: "fire"))
                        .AddItem(new ApplicationMenuItem("4h13", "报表", $"test2?a={new Random().NextDouble()}", icon: "fire"))
                 )
                 .AddItem(new ApplicationMenuItem("OperatingMmanager2", "工程建设行业", $"test2?a={new Random().NextDouble()}", icon: "aim")
                      .AddItem(new ApplicationMenuItem("h5133", "设备管理", $"test2?a={new Random().NextDouble()}", icon: "fire"))
                 )
              
          );

        //财务管理
        context.Menu.Items.Insert(
          7, new ApplicationMenuItem("DocumentMmanager", l["Menu:DocumentMmanager"], $"test2?a={new Random().NextDouble()}", icon: "account-book")
          );



        context.Menu.Items.Insert(
        8, new ApplicationMenuItem(ERPMenus.Table, "常用组件domo", "#", icon: "reddit")
             .AddItem(new ApplicationMenuItem("dome.table", "综合表格", "test2", icon: "table"))
        );

        return Task.CompletedTask;
    }

    private Task ConfigureUserMenuAsync(MenuConfigurationContext context)
    {
        var accountStringLocalizer = context.GetLocalizer<AccountResource>();

        var identityServerUrl = _configuration["AuthServer:Authority"] ?? "";

        context.Menu.AddItem(new ApplicationMenuItem(
            "Account.Manage",
            accountStringLocalizer["MyAccount"],
            $"{identityServerUrl.EnsureEndsWith('/')}Account/Manage?returnUrl={_configuration["App:SelfUrl"]}",
            icon: "fa fa-cog",
            order: 1000,
            null));

        return Task.CompletedTask;
    }
}

